<template>
  <div class="settings-page">
  <div class="container page">
    <div class="row">
      <div class="col-md-6 offset-md-3 col-xs-12">
        <h1 class="text-xs-center">Your Settings</h1>
        <form @submit.prevent="updateUser">
          <fieldset>
              <fieldset class="form-group">
                <input class="form-control" type="text" placeholder="URL of profile picture" v-model.trim="user.image">
              </fieldset>
              <fieldset class="form-group">
                <input class="form-control form-control-lg" type="text" placeholder="Your Name" v-model.trim="user.username">
              </fieldset>
              <fieldset class="form-group">
                <textarea class="form-control form-control-lg" rows="8" placeholder="Short bio about you" v-model.trim="user.bio"></textarea>
              </fieldset>
              <fieldset class="form-group">
                <input class="form-control form-control-lg" type="text" placeholder="Email" v-model.trim="user.email">
              </fieldset>
              <fieldset class="form-group">
                <input class="form-control form-control-lg" type="password" placeholder="Password" v-model.trim="user.password">
              </fieldset>
              <button class="btn btn-lg btn-primary pull-xs-right">
                Update Settings
              </button>
          </fieldset>
        </form>

        <hr />

        <button class="btn btn-outline-danger" @click.prevent="loginOut">
          Or click here to logout.
        </button>
      </div>
    </div>
  </div>
</div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name:'SettingsPages',
  data () {
    return {
       
    }
  },
  methods: {
    updateUser(){
      this.$store.dispatch('updataUser', this.user)
      // 更新完成跳转页面
      this.$router.push('/profile/' + this.user.username)
    },
    // 退出
    loginOut(){
      let flag = confirm('您确定要退出吗？')
      if(flag){
        this.$store.dispatch('resetUser')
        this.$router.replace('/')
      }
    }
  },
  computed: {
    ...mapState({
      user: state => state.user
    })
  },
}

</script>
<style lang='less' scoped>
</style>